<template>
  <div class="search">
    <f-drawer ref="processDrawer" :title="drawerTitle" width="50%" @submit="handleSubmit" @visibleChange="visibleChange">
      <a-tabs @tabClick="tabClick" :defaultActiveKey="current" v-model="current">
        <a-tab-pane tab="流程授权" key="form1" v-if="isEdit">
          <process-auth ref="form1" v-if="drawerVisible"></process-auth>
        </a-tab-pane>
      </a-tabs>
    </f-drawer>
  </div>
</template>
<script>
  import processForm from './process_form.vue'
  import ProcessAuth from './process_auth'

  export default {
    name: 'processDrawer',
    props: {},
    data() {
      return {
        refs: this.$refs,
        drawerVisible: false,
        isEdit: false,
        title: '',
        current: 'form1',
        formData: {},
        forms: [
          'form1',
          'form2',
          'form3'
        ]
      }
    },
    methods: {
      handleShow(data) {
        this.isEdit = false
        if (data && data.processId) {
          this.isEdit = true
          this.formData = data
        } else {
          this.formData = {}
        }
        this.refs['processDrawer'].show()
        this.tabClick('form1')
      },
      tabClick(name) {
        this.current = name
        if (this.current === this.forms[0]) {
          this.title = this.isEdit ? '编辑流程' : '添加流程'
        }
        if (this.current === this.forms[1]) {
          this.title = '流程授权'
        }
        if (this.current === this.forms[2]) {
          this.title = '流程图'
        }
        this.$nextTick(() => {
          this.$refs[this.current].setData(this.formData)
        })
      },
      handleSubmit(callback) {
        this.refs[this.current].handleSubmit(callback)
      },
      visibleChange(drawerVisible) {
        this.drawerVisible = drawerVisible
      }
    },
    computed: {
      drawerTitle: function() {
        return this.title
      }
    },
    created() {
    },
    components: { ProcessAuth, processForm }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
